package com.exam.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.exam.mapper.PositionMapper;
import com.exam.pojo.entity.Position;
import com.exam.service.PositionService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PositionServiceImpl implements PositionService {
    @Resource
    private PositionMapper positionMapper;

    /**
     * 根据部门查岗位
     * @param departmentId
     * @return
     */
    @Override
    public List<Position> findPositionListByDepartmentId(Integer departmentId) {
        LambdaQueryWrapper<Position> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Position::getDepartmentId,departmentId);
        return positionMapper.selectList(queryWrapper);
    }

    /**
     * 根据 positionId 查询 departmentId
     * @return
     */
    @Override
    public Integer findDepartmentIdByPositionId(Integer positionId){
        LambdaQueryWrapper<Position> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(Position::getDepartmentId);
        queryWrapper.eq(Position::getId,positionId);
        queryWrapper.last("limit 1");
        return positionMapper.selectOne(queryWrapper).getDepartmentId();
    }
}
